﻿using Action = Styx.TreeSharp.Action;
using Styx;
using Styx.Common;
using Styx.CommonBot;
using Styx.CommonBot.Routines;
using Styx.TreeSharp;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Diagnostics;

namespace Spriest
{
    public partial class Classname : CombatRoutine
    {
        public override string Name { get { return "Shadow Priest by Pasterke"; } }

        public override WoWClass Class { get { return WoWClass.Priest; } }

        LocalPlayer Me { get { return StyxWoW.Me; } }

        public override bool WantButton { get { return true; } }

        public bool stopAoe = false;

        private static ulong lastGuid = 0;

        private static Stopwatch pullTimer = new Stopwatch();

        private static Stopwatch fightTimer = new Stopwatch();

        private float naarTarget = 35f;

        public bool RemoveDeadTargets = true;

        private double MyTargetDistance
        {
            get
            {
                return Me.CurrentTarget != null ? Me.CurrentTarget.Distance : uint.MaxValue - 5;
            }
        }

        public override void OnButtonPress()
        {
            Form1 ConfigForm = new Form1();
            ConfigForm.ShowDialog();
        }
        public override void Initialize()
        {
            Updater.CheckForUpdate();
            Lua.Events.AttachEvent("MODIFIER_STATE_CHANGED", HandleModifierStateChanged);
        }
        #region CC_Begin

        public override void Pulse()
        {
            try
            {
                if (Me.Combat && RemoveDeadTargets && Me.CurrentTarget.IsFriendly)
                {
                    Me.ClearTarget();
                    return;
                }
                if (Me.Combat && RemoveDeadTargets && Me.CurrentTarget.IsDead)
                {
                    Me.ClearTarget();
                    return;
                }
            }
            catch { }
        }

        public override bool NeedRest
        {
            get
            {
                if (UseSpells)
                {
                    if (SpellManager.HasSpell(FlashHeal)
                        && Me.HealthPercent > SpriestSettings.myPrefs.eatfood
                        && Me.HealthPercent <= SpriestSettings.myPrefs.FlashHealPercentOOC)
                    {
                        return true;
                    }
                    if (Me.HealthPercent > SpriestSettings.myPrefs.eatfood
                        && SpellManager.HasSpell(Renew)
                        && Me.HealthPercent <= SpriestSettings.myPrefs.RenewPercentOOC
                        && Me.HealthPercent > SpriestSettings.myPrefs.FlashHealPercentOOC)
                    {
                        return true;
                    }
                    if (Me.ManaPercent < SpriestSettings.myPrefs.drinkmana)
                    {
                        return true;
                    }
                    if (Me.HealthPercent < SpriestSettings.myPrefs.eatfood)
                    {
                        return true;
                    }
                }
                return false;
            }
        }

        public override void Rest()
        {
            if (UseSpells)
            {
                if (Me.ManaPercent < SpriestSettings.myPrefs.drinkmana
                    && !Me.IsSwimming)
                {
                    Styx.CommonBot.Rest.Feed();
                }
                if (Me.HealthPercent < SpriestSettings.myPrefs.eatfood
                    && !Me.IsSwimming)
                {
                    Styx.CommonBot.Rest.Feed();
                }
                if (SpellManager.HasSpell(FlashHeal)
                    && Me.HealthPercent > SpriestSettings.myPrefs.eatfood
                    && Me.HealthPercent <= SpriestSettings.myPrefs.FlashHealPercentOOC
                    && !Me.HasAura("Drink")
                    && !Me.HasAura("Food"))
                {
                    if (SpellManager.HasSpell(FlashHeal))
                    {
                        if (SpellManager.CanCast(FlashHeal))
                        {
                            SpellManager.Cast(FlashHeal, Me);
                            LogMsg("Flash Heal", 2);
                            LastSpellID = FlashHeal;
                        }
                    }
                }
                if (SpellManager.HasSpell(Renew)
                    && !buffExists(Renew, Me)
                    && Me.HealthPercent > SpriestSettings.myPrefs.eatfood
                    && (Me.HealthPercent <= SpriestSettings.myPrefs.RenewPercentOOC
                    && Me.HealthPercent > SpriestSettings.myPrefs.FlashHealPercentOOC)
                    && !Me.HasAura("Drink")
                    && !Me.HasAura("Food"))
                {
                    if (SpellManager.HasSpell(Renew))
                    {
                        if (SpellManager.CanCast(Renew))
                        {
                            SpellManager.Cast(Renew, Me);
                            LogMsg("Renew", 2);
                            LastSpellID = Renew;
                        }
                    }
                }
                if (SpellManager.HasSpell(ShadowForm)
                    && !buffExists(ShadowForm, Me)
                    && Me.HealthPercent > SpriestSettings.myPrefs.FlashHealPercentOOC)
                {
                    if (SpellManager.CanCast(ShadowForm))
                    {
                        SpellManager.Cast(ShadowForm);
                        LogMsg("Shadow Form", 2);
                        LastSpellID = ShadowForm;
                    }
                }
            }
        }

        #endregion

        #region Pull

        public override void Pull()
        {
            if (!SpriestSettings.myPrefs.targetting)
            {
                EnsureTarget();
            }
            if (Battlegrounds.IsInsideBattleground)
            {
                if (Me.GotTarget &&
                    Me.CurrentTarget.IsPet)
                {
                    Blacklist.Add(Me.CurrentTarget, TimeSpan.FromDays(1));
                    Me.ClearTarget();
                }

                if (gotTarget 
                    && Me.CurrentTarget.Mounted)
                {
                    Blacklist.Add(Me.CurrentTarget, TimeSpan.FromMinutes(1));
                    Me.ClearTarget();
                }
            }
            if (gotTarget
                && !Me.CurrentTarget.InLineOfSight
                && !SpriestSettings.myPrefs.movement)
            {
                MoveInLignOfSight();
            }
            if (gotTarget
                && Me.CurrentTarget.Distance > naarTarget
                && !SpriestSettings.myPrefs.movement)
            {
                MoveInRange(naarTarget);
            }
            else
            {
                if (Me.IsMoving)
                {
                    WoWMovement.MoveStop();
                }
                if (!SpriestSettings.myPrefs.facing)
                {
                    Me.CurrentTarget.Face();
                } 

                if (gotTarget
                    && Me.Level < 3)
                {
                    MoveInRange(25);
                    if (Me.IsMoving)
                    {
                        WoWMovement.MoveStop();
                    }
                    Me.CurrentTarget.Face();

                    SpellManager.Cast(Smite);
                    LogMsg("Pull with Smite", 6);
                }
                if (gotTarget
                    && SpellManager.HasSpell(DevouringPlague)
                    && Me.GetCurrentPower(WoWPowerType.ShadowOrbs) >= SpriestSettings.myPrefs.shadoworbs
                    && SpriestSettings.myPrefs.pullDevPlag)
                {
                    if (SpellManager.CanCast(DevouringPlague))
                    {
                        SpellManager.Cast(DevouringPlague);
                        LogMsg("Pull with Devouring Plague", 6);
                    }
                }
                if (gotTarget
                    && SpellManager.HasSpell(ShadowWordPain)
                    && !debuffExists(ShadowWordPain, Me.CurrentTarget))
                {
                    SpellManager.Cast(ShadowWordPain);
                    LogMsg("Pull with Shadow Word: Pain", 6);
                }
            }


        }


        #endregion

        #region Pull Buffs

        public override bool NeedPullBuffs
        {
            get
            {
                if (SpellManager.HasSpell(ShadowForm)
                    && !buffExists(ShadowForm, Me))
                {
                    if (SpellManager.CanCast(ShadowForm))
                    {
                        SpellManager.Cast(ShadowForm);
                        LogMsg("Shadow Form", 2);
                        LastSpellID = ShadowForm;
                    }
                }
                return false;
            }
        }

        public override void PullBuff() { }

        #endregion

        #region Pre Combat Buffs

        public override bool NeedPreCombatBuffs
        {
            get
            {
                if (UseSpells)
                {
                    AlchemistFlask();

                    if (SpellManager.HasSpell(PowerWordFortitude)
                        && !buffExists(PowerWordFortitude, Me))
                    {
                        if (SpellManager.CanCast(PowerWordFortitude))
                        {
                            SpellManager.Cast(PowerWordFortitude, Me);
                            LogMsg("Power Word: Fortitude", 2);
                            LastSpellID = PowerWordFortitude;
                        }
                    }
                    if (SpellManager.HasSpell(InnerFire)
                        && !buffExists(InnerFire, Me))
                    {
                        if (SpellManager.CanCast(InnerFire))
                        {
                            SpellManager.Cast(InnerFire, Me);
                            LogMsg("Inner Fire", 2);
                            LastSpellID = InnerFire;
                        }
                    }
                    if (SpellManager.HasSpell(ShadowForm)
                        && !buffExists(ShadowForm, Me))
                    {
                        if (SpellManager.CanCast(ShadowForm))
                        {
                            SpellManager.Cast(ShadowForm);
                            LogMsg("Shadow Form", 2);
                            LastSpellID = ShadowForm;
                        }
                    }
                }
                return false; ;
            }
        }

        public override void PreCombatBuff() { }

        #endregion

        #region Combat Buffs

        public override bool NeedCombatBuffs
        {
            get
            {
                AlchemistFlask();

                UseEngiBelt();

                HealthStone();

                if (SpellManager.HasSpell(PowerWordFortitude)
                        && !buffExists(PowerWordFortitude, Me))
                {
                    if (SpellManager.CanCast(PowerWordFortitude))
                    {
                        SpellManager.Cast(PowerWordFortitude, Me);
                        LogMsg("Power Word: Fortitude", 2);
                        LastSpellID = PowerWordFortitude;
                    }
                }
                if (SpellManager.HasSpell(InnerFire)
                    && !buffExists(InnerFire, Me))
                {
                    if (SpellManager.CanCast(InnerFire))
                    {
                        SpellManager.Cast(InnerFire, Me);
                        LogMsg("Inner Fire", 2);
                        LastSpellID = InnerFire;
                    }
                }
                if (SpellManager.HasSpell(ShadowForm)
                    && !buffExists(ShadowForm, Me))
                {
                    if (SpellManager.CanCast(ShadowForm))
                    {
                        SpellManager.Cast(ShadowForm);
                        LogMsg("Shadow Form", 2);
                        LastSpellID = ShadowForm;
                    }
                }

                if (gotTarget
                    && SpellManager.HasSpell(Dispersion)
                    && !spellOnCooldown(Dispersion)
                    && (Me.ManaPercent <= SpriestSettings.myPrefs.dispersionmana
                    || Me.HealthPercent <= SpriestSettings.myPrefs.dispersionhealth))
                {
                    if (SpellManager.CanCast(Dispersion))
                    {
                        SpellManager.Cast(Dispersion);
                        LogMsg("Dispersion", 2);
                        LastSpellID = Dispersion;
                    }
                }
                if (gotTarget
                    && SpriestSettings.myPrefs.DesperatePrayerYorN == 1
                    && SpellManager.HasSpell(DesperatePrayer)
                    && !spellOnCooldown(DesperatePrayer)
                    && Me.HealthPercent <= SpriestSettings.myPrefs.DesperatePrayerPercent)
                {
                    if (SpellManager.CanCast(DesperatePrayer))
                    {
                        SpellManager.Cast(DesperatePrayer, Me);
                        LogMsg("Desperate Prayer", 2);
                        LastSpellID = DesperatePrayer;
                    }
                }
                if (gotTarget
                    && SpellManager.HasSpell(PowerWordShield)
                    && !spellOnCooldown(PowerWordShield)
                    && !buffExists(PowerWordShield, Me)
                    && Me.HealthPercent <= SpriestSettings.myPrefs.PowerWordShieldPercent)
                {
                    if (SpellManager.CanCast(PowerWordShield))
                    {
                        SpellManager.Cast(PowerWordShield, Me);
                        LogMsg("Power Word: Shield", 2);
                        LastSpellID = PowerWordShield;
                        SpellManager.Cast(FlashHeal);
                        LogMsg("Flash Heal with Power Word: Shield", 2);
                        LastSpellID = FlashHeal;
                    }
                }
                if (gotTarget
                    && SpellManager.HasSpell(FlashHeal)
                    && Me.HealthPercent <= SpriestSettings.myPrefs.FlashHealPercent)
                {
                    if (SpellManager.CanCast(FlashHeal))
                    {
                        SpellManager.Cast(FlashHeal, Me);
                        LogMsg("Flash Heal", 2);
                        LastSpellID = FlashHeal;
                    }
                }
                if (SpellManager.HasSpell(Renew)
                    && !buffExists(Renew, Me)
                    && Me.HealthPercent <= SpriestSettings.myPrefs.RenewPercent)
                {
                    if (SpellManager.CanCast(Renew))
                    {
                        SpellManager.Cast(Renew, Me);
                        LogMsg("Renew", 2);
                        LastSpellID = Renew;
                    }
                }
                if (gotTarget
                    && SpellManager.HasSpell(GiftOfTheNaruu)
                    && !spellOnCooldown(GiftOfTheNaruu)
                    && Me.HealthPercent <= SpriestSettings.myPrefs.naruupercent)
                {
                    if (SpellManager.CanCast(GiftOfTheNaruu))
                    {
                        SpellManager.Cast(GiftOfTheNaruu);
                        LogMsg("Gift of the Naruu", 2);
                        LastSpellID = GiftOfTheNaruu;
                    }
                }
                if (gotTarget
                    && SpellManager.HasSpell(VampiricEmbrace)
                    && !spellOnCooldown(VampiricEmbrace)
                    && Me.HealthPercent <= SpriestSettings.myPrefs.VampiricEmbracePercent)
                {
                    if (SpellManager.CanCast(VampiricEmbrace))
                    {
                        SpellManager.Cast(VampiricEmbrace);
                        LogMsg("Vampiric Embrace", 2);
                        LastSpellID = VampiricEmbrace;
                    }
                }
                if (gotTarget
                    && SpellManager.HasSpell(FearWard)
                    && SpriestSettings.myPrefs.FearWard
                    && !buffExists(FearWard, Me)
                    && !spellOnCooldown(FearWard))
                {
                    if (SpellManager.CanCast(FearWard))
                    {
                        SpellManager.Cast(FearWard, Me);
                        LogMsg("Fear Ward", 2);
                        lastCast = FearWard;
                    }
                }

                return false;
            }
        }

        public override void CombatBuff()
        {

        }

        #endregion

        #region Heal

        public override bool NeedHeal { get { return false; } }

        public override void Heal()
        {

        }

        #endregion

        #region Falling

        public void HandleFalling() { }

        #endregion

        #region Combat

        public override void Combat()
        {
            if (Paused)
            {
                return;
            }
            if (UseSpells)
            {
                if (!Me.GotTarget
                    && !SpriestSettings.myPrefs.targetting)
                {
                    EnsureTarget();
                }
                if (gotTarget
                    && !Me.CurrentTarget.InLineOfSight
                    && !SpriestSettings.myPrefs.movement)
                {
                    MoveInLignOfSight();
                }
                if (gotTarget
                    && !SpriestSettings.myPrefs.movement)
                {
                    MoveInRange(35);
                }
                if (gotTarget
                    && !SpriestSettings.myPrefs.facing)
                {
                    Me.CurrentTarget.Face();
                }

                if (gotTarget
                    && addCount >= SpriestSettings.myPrefs.startaoe
                    && !DisableAoe
                    && ((SpriestSettings.myPrefs.usemindsear == 1 && (Me.GroupInfo.IsInParty || Me.GroupInfo.IsInRaid || Me.IsInInstance))
                    || SpriestSettings.myPrefs.usemindsear == 2)
                    && SpellManager.HasSpell(MindSear))
                {
                    if (gotTarget
                        && SpellManager.HasSpell(Cascade)
                        && !spellOnCooldown(Cascade)
                        && SpellManager.CanCast(Cascade))
                    {
                        SpellManager.Cast(Cascade);
                        LogMsg("Cascade Aoe", 6);
                        LastSpellID = Cascade;

                    }
                    if(gotTarget
                        && SpellManager.HasSpell(MindSear)
                        && SpellManager.CanCast(MindSear)
                        && SpriestSettings.myPrefs.usemindsear == 3
                        && Me.FocusedUnit != null
                        && !Me.IsChanneling)
                    {
                        Me.FocusedUnit.Target();
                        SpellManager.Cast(MindSear);
                        LogMsg("Mind Sear Aoe on Focused Unit", 6);
                        LastSpellID = MindSear;
                    }

                    if (gotTarget
                        && SpellManager.HasSpell(MindSear)
                        && SpellManager.CanCast(MindSear)
                        && !Me.IsChanneling)
                    {
                        SpellManager.Cast(MindSear);
                        LogMsg("Mind Sear Aoe", 6);
                        LastSpellID = MindSear;
                    }
                    return;
                }

                if (gotTarget
                    && SpellManager.HasSpell(ShadowWordDeath)
                    && !spellOnCooldown(ShadowWordDeath)
                    && Me.CurrentTarget.HealthPercent <= 20)
                {
                    if (SpellManager.CanCast(ShadowWordDeath))
                    {
                        SpellManager.Cast(ShadowWordDeath);
                        LogMsg("Shadow Word: Death", 7);
                        LastSpellID = ShadowWordDeath;
                        return;
                    }
                }
                if (gotTarget
                    && SpellManager.HasSpell(DevouringPlague)
                    && ((Me.GetCurrentPower(WoWPowerType.ShadowOrbs) >= SpriestSettings.myPrefs.shadoworbs && !IsBoss && Me.CurrentTarget.HealthPercent > 20)
                    || (Me.GetCurrentPower(WoWPowerType.ShadowOrbs) >= 3 && IsBoss))
                    && SpellManager.CanCast(DevouringPlague))
                {
                    SpellManager.Cast(DevouringPlague);
                    LogMsg("Devouring Plague", 0);
                    LastSpellID = DevouringPlague;
                }
                myFlask();

                myPotion();

                UseTrinket1();

                UseTrinket2();

                UseEngiGloves();

                if (gotTarget
                    && SpellManager.HasSpell(PowerInfusion)
                    && SpriestSettings.myPrefs.insanity == 1
                    && !spellOnCooldown(PowerInfusion)
                    && debuffExists(DevouringPlague, Me.CurrentTarget))
                {
                    if (SpellManager.CanCast(PowerInfusion))
                    {
                        SpellManager.Cast(PowerInfusion);
                        LogMsg("Power Infusion", 4);
                        LastSpellID = PowerInfusion;
                    }
                }

                if (gotTarget
                    && SpriestSettings.myPrefs.insanity == 1
                    && debuffExists(DevouringPlague, Me.CurrentTarget)
                    && SpellManager.HasSpell(MindFlay)
                    && !Me.IsChanneling
                    && SpellManager.CanCast(MindFlay))
                {
                    SpellManager.Cast(MindFlay);
                    LogMsg("Mind Flay Insanity", 1);
                    LastSpellID = MindFlay;
                    return;
                }

                if (gotTarget
                    && SpellManager.HasSpell(FromDarknessComesLight)
                    && SpriestSettings.myPrefs.DarknessLight == 1
                    && buffExists("Surge of Darkness", Me))
                {
                    if (SpellManager.CanCast(MindSpike))
                    {
                        SpellManager.Cast(MindSpike);
                        LogMsg("Mind Spike", 5);
                        LastSpellID = MindSpike;
                        return;
                    }
                }
                if (gotTarget
                    && SpellManager.HasSpell(ShackleUndead)
                    && Me.CurrentTarget.IsUndead
                    && Me.CurrentTarget.IsPlayer
                    && !debuffExists(ShackleUndead, Me.CurrentTarget)
                    && !spellOnCooldown(ShackleUndead))
                {
                    if (SpellManager.CanCast(ShackleUndead))
                    {
                        SpellManager.Cast(ShackleUndead);
                        if (debuffExists(ShackleUndead, Me.CurrentTarget))
                        {
                            Me.ClearTarget();
                        }
                        LogMsg("Shackle Undead", 2);
                        LastSpellID = ShackleUndead;
                    }
                }



                if (gotTarget
                    && SpellManager.HasSpell(Smite)
                    && !SpellManager.HasSpell(MindFlay))
                {
                    if (SpellManager.CanCast("Smite"))
                    {
                        SpellManager.Cast("Smite");
                        LogMsg("Smite", 3);
                    }
                }
                if (gotTarget
                    && SpellManager.HasSpell(Silence)
                    && !spellOnCooldown(Silence)
                    && SpriestSettings.myPrefs.silence == 1
                    && (Me.CurrentTarget.IsCasting
                    && Me.CanInterruptCurrentSpellCast))
                {
                    if (SpellManager.CanCast(Silence))
                    {
                        SpellManager.Cast(Silence);
                        LogMsg("Silence", 5);
                        LastSpellID = Silence;
                    }
                }
                if (gotTarget
                    && SpellManager.HasSpell(PsychicScream)
                    && !spellOnCooldown(PsychicScream)
                    && addCount > SpriestSettings.myPrefs.psyscreamadds
                    && SpriestSettings.myPrefs.psyscream == 1)
                {
                    if (SpellManager.CanCast(PsychicScream))
                    {
                        SpellManager.Cast(PsychicScream);
                        LogMsg("Psychic Scream", 2);
                        LastSpellID = PsychicScream;
                    }
                }
                if (usevoidtendrils())
                {
                    if (SpellManager.CanCast(VoidTendrils))
                    {
                        SpellManager.Cast(VoidTendrils);
                        LogMsg("Void Tendrils", 9);
                        LastSpellID = VoidTendrils;
                    }
                    if (buffExists(VoidTendrils, Me.CurrentTarget))
                    {
                        MoveBack(WoWMovement.MovementDirection.Backwards);
                    }
                }
                if (gotTarget
                    && SpellManager.HasSpell(VampiricTouch)
                    && (!debuffExists(VampiricTouch, Me.CurrentTarget)
                    || debuffTimeLeft(VampiricTouch, Me.CurrentTarget) < 4000)
                    && LastSpellID != VampiricTouch)
                {
                    if (SpellManager.CanCast(VampiricTouch))
                    {
                        SpellManager.Cast(VampiricTouch);
                        LogMsg("Vampiric Touch", 0);
                        LastSpellID = VampiricTouch;
                    }
                }
                if (gotTarget
                    && SpellManager.HasSpell(ShadowWordPain)
                    && (!debuffExists(ShadowWordPain, Me.CurrentTarget)
                    || debuffTimeLeft(ShadowWordPain, Me.CurrentTarget) < 4000)
                    && LastSpellID != ShadowWordPain)
                {
                    if (SpellManager.CanCast(ShadowWordPain))
                    {
                        SpellManager.Cast(ShadowWordPain);
                        LogMsg("Shadow Word: Pain", 1);
                        LastSpellID = ShadowWordPain;
                    }
                }



                if (usemindbender())
                {
                    if (SpellManager.CanCast(MindBinder))
                    {
                        SpellManager.Cast(MindBinder);
                        LogMsg("Mindbender", 9);
                        LastSpellID = MindBinder;

                        if (SpellManager.HasSpell(Fade)
                        && !spellOnCooldown(Fade))
                        {
                            if (SpellManager.CanCast(Fade))
                            {
                                SpellManager.Cast(Fade);
                                LogMsg("Fade", 2);
                                LastSpellID = Fade;
                            }
                        }
                    }
                }
                if (useshadowfiend())
                {
                    if (SpellManager.CanCast(ShadowFiend))
                    {
                        SpellManager.Cast(ShadowFiend);
                        LogMsg("Shadowfiend", 9);
                        LastSpellID = ShadowFiend;

                        if (SpellManager.HasSpell(Fade)
                        && !spellOnCooldown(Fade))
                        {
                            if (SpellManager.CanCast(Fade))
                            {
                                SpellManager.Cast(Fade);
                                LogMsg("Fade", 2);
                                LastSpellID = Fade;
                            }
                        }
                    }
                }
                if (uselifeblood())
                {
                    if (SpellManager.CanCast(Lifeblood))
                    {
                        SpellManager.Cast(Lifeblood);
                        LogMsg("Lifeblood", 10);
                        LastSpellID = Lifeblood;
                    }
                }

                if (usecascade())
                {
                    if (SpellManager.CanCast(Cascade))
                    {
                        SpellManager.Cast(Cascade);
                        LogMsg("Cascade", 0);
                        LastSpellID = Cascade;
                    }
                }
                if (useDivineStar())
                {
                    if (SpellManager.CanCast(DivineStar))
                    {
                        SpellManager.Cast(DivineStar);
                        LogMsg("Halo", 0);
                        LastSpellID = DivineStar;
                    }
                }
                if (useHalo())
                {
                    if (SpellManager.CanCast(Halo))
                    {
                        SpellManager.Cast(Halo);
                        LogMsg("Halo", 0);
                        LastSpellID = Halo;
                    }
                }
                if (usepowerinfusion())
                {
                    if (SpellManager.CanCast(PowerInfusion))
                    {
                        SpellManager.Cast(PowerInfusion);
                        LogMsg("Power Infusion", 1);
                        LastSpellID = PowerInfusion;
                    }
                }

                if (usedivineinsight())
                {
                    if (SpellManager.CanCast(MindBlast))
                    {
                        SpellManager.Cast(MindBlast);
                        LogMsg("Mind Blast Divine Insight", 6);
                        LastSpellID = MindBlast;
                    }
                }
                if (usemindblast())
                {
                    if (SpellManager.CanCast(MindBlast))
                    {
                        SpellManager.Cast(MindBlast);
                        LogMsg("Mind Blast", 3);
                        LastSpellID = MindBlast;

                    }
                }
                if (gotTarget
                    && SpellManager.HasSpell(MindFlay)
                    && dotOnTarget
                    && !Me.IsChanneling)
                {
                    if (SpellManager.CanCast(MindFlay))
                    {
                        SpellManager.Cast(MindFlay);
                        LogMsg("Mind Flay", 3);
                        LastSpellID = MindFlay;

                    }
                }
            }
        }

        #endregion

        #region MainRotation

        public void MainRotation()
        { }





        #endregion MainRotation

        public void AutoAttack()
        {
            Lua.DoString("StartAttack();");
        }
    }
}
